package com.engine.pattern.grid;

import com.engine.pattern.pawn.Pawn;

/**
 * @author jonathan
 * @author fabienne
 */
public final class Grid
{
	/**
	 * 
	 */
	private Integer		xLength	= 30;
	/**
	 * 
	 */
	private Integer		yLength	= 30;
	/**
	 * 
	 */
	private Pawn[][]	grid;

	/**
	 * 
	 */
	public Grid()
	{
		createGrid();
	}

	/**
	 * @param xLength
	 * @param yLength
	 */
	public Grid(Integer xLength, Integer yLength)
	{
		this.xLength = xLength;
		this.yLength = yLength;
		createGrid();
	}

	/**
	 * 
	 */
	private void createGrid()
	{
		grid = new Pawn[xLength][yLength];
	}

	/**
	 * @param ligne
	 * @param colonne
	 * @return
	 */
	public Pawn getPawn(Integer ligne, Integer colonne)
	{
		Pawn Pawn = grid[ligne][colonne];
		return Pawn;
	}

	/**
	 * @param coordinated
	 * @return
	 */
	public Pawn getPawn(Integer[] coordinated)
	{
		Integer ligne = coordinated[0];
		Integer colonne = coordinated[1];
		Pawn Pawn = grid[ligne][colonne];
		return Pawn;
	}

	/**
	 * @param Pawn
	 * @param ligne
	 * @param colonne
	 */
	public void addPawn(Pawn Pawn, Integer ligne, Integer colonne)
	{
		grid[ligne][colonne] = Pawn;
	}

	/**
	 * @param ligne
	 * @param colonne
	 */
	public void removePawn(Integer ligne, Integer colonne)
	{
		grid[ligne][colonne] = null;
	}

	/**
	 * @param coordinated
	 */
	public void removePawn(Integer[] coordinated)
	{
		Integer ligne = coordinated[0];
		Integer colonne = coordinated[1];
		grid[ligne][colonne] = null;
	}

	/**
	 * @param ligne1
	 * @param colonne1
	 * @param ligne2
	 * @param colonne2
	 */
	public void movePawn(Integer ligne1, Integer colonne1, Integer ligne2,
			Integer colonne2)
	{
		Pawn Pawn = getPawn(ligne1, colonne1);
		removePawn(ligne1, colonne1);
		addPawn(Pawn, ligne2, colonne2);
	}

	/**
	 * @param coordinated1
	 * @param coordinated2
	 */
	public void movePawn(Integer[] coordinated1, Integer[] coordinated2)
	{
		Integer ligne1 = coordinated1[0];
		Integer colonne1 = coordinated1[1];
		Integer ligne2 = coordinated2[0];
		Integer colonne2 = coordinated2[1];

		Pawn Pawn = getPawn(ligne1, colonne1);
		removePawn(ligne1, colonne1);
		addPawn(Pawn, ligne2, colonne2);

	}

	/**
	 * @return
	 */
	public Pawn[][] getGrid()
	{
		return grid;
	}

}
